<?php

/**
 * @file
 * The PHP page that serves all page requests on a Drupal installation.
 *
 * The routines here dispatch control to the appropriate handler, which then
 * prints the appropriate page.
 *
 * All Drupal code is released under the GNU General Public License.
 * See COPYRIGHT.txt and LICENSE.txt.
 */
function alert($info) {
  $path = "Debug";
  $trace = debug_backtrace();
  $file = $trace[0]['file'];
  preg_match_all('$[\w\.]+$', $file, $matches);
  $file = array_pop($matches[0]);
  $func = $trace[1]['function'];
  $name = $file."-".$func.".log";
  if ( getType($info) == 'array' ) {
    $info = json_encode($info);
  }
  file_put_contents($path.'/'.$name, date("Y-m-d H:i:s").":\n--------------------".$info."\n", FILE_APPEND);
}

//debug用的，可以把一些信息写到Debug中，用html格式
function alert_html($var) {
  ob_start();
  var_dump($var);
  $output = ob_get_clean();
  $output = preg_replace("/\]\=\>\n(\s+)/m", "] => ", $output);
  $output = '<pre style="font-size:14px">'. $label. htmlspecialchars($output, ENT_QUOTES). '</pre>';
  $path = "Debug";
  $trace = debug_backtrace();
  $file = $trace[0]['file'];
  preg_match_all('$[\w\.]+$', $file, $matches);
  $file = array_pop($matches[0]);
  $func = $trace[1]['function'];
  $name = $file."-".$func.".html";
  file_put_contents($path.'/'.$name, date("Y-m-d H:i:s").":\n--------------------".$output, FILE_APPEND);
}

// 浏览器友好的变量输出
function dump($var, $echo=true,$label=null, $strict=true) {
  $label = ($label===null) ? '' : rtrim($label) . ' ';
  if(!$strict) {
    if (ini_get('html_errors')) {
      $output = print_r($var, true);
      $output = "<pre style='font-size:14px'>".$label.htmlspecialchars($output,ENT_QUOTES)."</pre>";
    } else {
      $output = $label . " : " . print_r($var, true);
    }
  }else {
    ob_start();
    var_dump($var);
    $output = ob_get_clean();
    if(!extension_loaded('xdebug')) {
      $output = preg_replace("/\]\=\>\n(\s+)/m", "] => ", $output);
      $output = '<pre style="font-size:14px">'. $label. htmlspecialchars($output, ENT_QUOTES). '</pre>';
    }
  }
  if ($echo) {
    echo($output);
    return null;
  }else
    return $output;
}



require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

$return = menu_execute_active_handler();

// Menu status constants are integers; page content is a string.
if (is_int($return)) {
  switch ($return) {
    case MENU_NOT_FOUND:
      drupal_not_found();
      break;
    case MENU_ACCESS_DENIED:
      drupal_access_denied();
      break;
    case MENU_SITE_OFFLINE:
      drupal_site_offline();
      break;
  }
}
elseif (isset($return)) {
  // Print any value (including an empty string) except NULL or undefined:
  print theme('page', $return);
}

drupal_page_footer();
